package cn.edu.zsc.blms.service.array;

import cn.edu.zsc.blms.App;
import cn.edu.zsc.blms.domain.BaseEntity;
import cn.edu.zsc.blms.exception.EntityNotExistException;

public abstract class BaseService {
    protected  final BaseEntity[] DATA = new BaseEntity[100];
    protected BaseEntity getEntity() throws EntityNotExistException{
        BaseEntity entity;
        try{
            int id = Integer.parseInt(App.input.nextLine());
            if(id >= DATA.length || DATA[id] == null){
                throw new EntityNotExistException();
            }
            entity = DATA[id];
        }catch(NumberFormatException e){
            throw  new EntityNotExistException("ID为整数, 请输入整数");
        }
        return entity;
    }
}
